<template>
  <div class="box">
    <!-- 面包屑区域 -->
    <el-breadcrumb separator="/" class="user-tou">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item>
        <el-input
          v-model="formInline.query"
          placeholder="请输入内容"
          class="input-with-select"
          clearable
          style="width: 200px"
          @clear="lierights"
        >
          <el-button slot="append" icon="el-icon-search" @click="lierights" />
        </el-input>
      </el-form-item>

      <!-- 列表项 -->
    </el-form>
    <!-- 卡片区域 -->
    <el-card class="box-card">
      <el-table :data="rightsfrom" border style="width: 100%">
        <el-table-column type="index" width="60" label="#" />
        <el-table-column prop="order_number" label="订单编号" />
        <el-table-column prop="order_price" label="订单价格" width="110" />

        <el-table-column prop="order_pay" label="是否付款">
          <template #default="{ row }">
            <el-tag type="succes" v-if="row.order_pay === '1'">已付款</el-tag>
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" />
        <el-table-column prop="create_time" label="下单时间">
          <template #default="{ row }">
            {{ row.create_time | update_time }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template #default="{ row }">
            <!-- //修改按钮 -->
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="showorders(row.order_id)"
              >编辑</el-button
            >
            <el-button
              icon="el-icon-delete"
              size="mini"
              type="success"
              @click="wuorders"
              >物流</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <div class="block">
        <el-pagination
          :page-sizes="[5, 10, 15]"
          :page-size="formInline.pagesize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :current-page="formInline.pagenum"
          background
          @size-change="goodsSizeChange"
          @current-change="goodsCurrentChange"
        >
          <!-- //使用了size-change和current-change事件来处理页码大小和当前页变动时候触发的事件。 -->
        </el-pagination>
      </div>
    </el-card>
    <!-- 修改地址对话框 -->
    <el-dialog title="修改订单" :visible.sync="ordersFormVisible">
      <el-form
        ref="ordesref"
        :model="ordersform"
        :rules="ordersrules"
        label-width="100px"
      >
        <el-form-item label="订单价格" prop="order_price">
          <el-input v-model="ordersform.order_price" type="number"></el-input>
        </el-form-item>
        <el-form-item label="是否付款">
          <el-radio-group v-model="ordersform.order_pay">
            <el-radio label="已付款"></el-radio>
            <el-radio label="未付款"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="是否发货">
          <el-radio-group v-model="ordersform.is_send">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="ordersFormdel">取 消</el-button>
        <el-button type="primary" @click="ordersFormVisible = false"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <el-dialog title="查看物流进度" :visible.sync="ordersForm" width="700px">
      <el-form
        ref="ordesref"
        :model="ordersform"
        :rules="ordersrules"
        label-width="100px"
      >
        <el-timeline :reverse="reverse">
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :timestamp="activity.ftime"
          >
            {{ activity.context }}
          </el-timeline-item>
        </el-timeline>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="ordersFormque">取 消</el-button>
        <el-button type="primary" @click="ordersForm = false">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { getgoods, getding, getwu } from "@/api/orders";
export default {
  name: "LoginIndex",
  data() {
    return {
      // 订单列表数据
      rightsfrom: [],
      value1: true,
      // 数据总条数
      total: 0,

      // 搜索框搜索内容
      formInline: {
        query: "", // 用户名
        pagenum: 1, // 当前页码数
        pagesize: 10, // 当前页数据条数
      },
      //展示修改地址对话框
      ordersFormVisible: false,
      //表单数据对象
      ordersform: {
        orderss1: [],
      },
      //表单验证
      ordersrules: {
        orderss1: [
          { required: true, message: "请选择订单价格", trigger: "blur" },
        ],
      },
      //物流显示隐藏
      ordersForm: false,
      //物流的进度
      reverse: false,
      activities: [],
    };
  },
  created() {
    this.lierights();
  },
  methods: {
    // 获取订单列表数据
    async lierights() {
      const res = await getgoods(this.formInline);
      // console.log(res);

      this.rightsfrom = res.data.goods;
      this.total = res.data.total;
    },
    // pagesize改变就会触发这个函数，我们将newPagesize赋值给pagesize，然后再刷新一下数据
    // 页码调用
    goodsSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.formInline.pagesize = val;
      this.lierights();
    },
    // 监听页码值
    goodsCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.formInline.pagenum = val;

      this.lierights();
    },
    //展开修改框
    async showorders(order_id) {
      const res = await getding(order_id);
      // console.log(res.data);
      this.ordersform = res.data;
      this.ordersFormVisible = true;
    },
    //关闭对话框
    ordersFormdel() {
      this.$refs.ordesref.resetFields();
      this.ordersFormVisible = false;
    },
    //物流点击按钮显示物流进度
    async wuorders() {
      const res = await getwu(1106975712662);
      // console.log(res.data);
      this.activities = res.data;
      this.ordersForm = true;
    },

    // 添加商品跳转路由
    goodspage() {
      this.$router.push("goods/app");
    },
    ordersFormque() {
      this.ordersForm = false;
    },
  },
};
</script>

<style lang="less" scoped>
.user-tou {
  margin-bottom: 15px;
}
</style>
